#pragma once
#include <vector>

namespace RSA
{
	typedef unsigned char uint8;
	typedef unsigned long uint32;

	struct rc4_state
	{
		uint32 x, y, m[256];
	};

	void rc4_setup( struct rc4_state *s, const uint8 *key, uint32 length );
	void rc4_crypt( struct rc4_state *s, uint8 *data, uint32 length );

	class RC4
	{
	public:
		            RC4(const std::vector<char> &key);
		void	    crypt(std::vector<char> &data);

	private:
		rc4_state   state;
	};

	inline RC4::RC4(const std::vector<char> &key)
	{	rc4_setup( &state, reinterpret_cast<const uint8 *>( &key[0] ), static_cast<uint32>( key.size() ) );  }

	inline void RC4::crypt(std::vector<char> &data)
	{	rc4_crypt( &state, reinterpret_cast<uint8 *>( &data[0] ), static_cast<uint32>( data.size() ) );  }
}